﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Data.Objects.DataClasses;

namespace University.Workshop.Model
{
    [Table("Kardex")]
    public class Kardex
    {

        [Key]
        public int KardexId { get; set; }

        //[Key]
        //[Column(Order = 1)]
        //[ForeignKey("Allotment")]
        //public int AllotmentId { get; set; }
        //[Key]
        //[Column(Order = 0)]
        [ForeignKey("Person")]
        public string ClientId { get; set; }

        public virtual Person Person { get; set; }
        public string WaterMeasurer { get; set; } //Medidor
        public bool Enable { get; set; }
        public bool HasAWaterMeasurer { get; set; }


        [NotMapped]
        public string EnableString
        {
            get { return Enable ? "Activo" : "Inactivo"; }
        }

        [NotMapped]
        public bool VisibilityButtonDisable
        {
            get { return (Enable) ; }
        }

        [NotMapped]
        public bool VisibilityButtonEnable
        {
            get { return ((!Enable) ); }
        }

        [NotMapped]
        public Allotment AllotmentModel
        {
            get
            {
                if (Allotment.Count == 1)
                    return Allotment.First();
                else
                    return null;
            }
            set
            {
                if (value == null)
                    Allotment = null;
                else
                    Allotment = new List<Allotment>()
                                    {
                                        value
                                    };
            }
        }


        public virtual ICollection<Allotment> Allotment { get; set; }
        public virtual ICollection<CollectControl> CollectsControls { get; set; }

        public virtual ICollection<Reconnection> Reconnections { get; set; }
        public virtual ICollection<CutSupply> CutSupplies { get; set; }
        public virtual ICollection<WaterReadingControl> WaterReadingControls { get; set; }

    }
}
